# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>

pkgname=roundcube-mobile
# NOTE: These 3 plugins/skins forms one product, they are not used separately
# anywhere, thus I put them together into single abuild.
_pkgname_plugin=Roundcube-Plugin-Mobile
_pkgname_skin=Roundcube-Skin-Melanie2-Larry-Mobile
_pkgname_jquery=Roundcube-Plugin-JQuery-Mobile
pkgver=0.4.9
pkgrel=0
_pkgver_jquery=1.2
pkgdesc="Mobile plugin and skin for Roundcube by Melanie2"
url="https://plugins.roundcube.net/packages/melanie2/mobile"
arch="noarch"
license="GPL-3.0-or-later CC-3.0-BY-SA"
depends="roundcubemail"
pkggroups="roundcube"
options="!check"  # no tests provided
subpackages="
	$pkgname-calendar:_plugin
	$pkgname-enigma:_plugin
	$pkgname-managesieve:_plugin
	"
source="https://github.com/messagerie-melanie2/$_pkgname_plugin/archive/v$pkgver/$_pkgname_plugin-$pkgver.tar.gz
	https://github.com/messagerie-melanie2/$_pkgname_skin/archive/v$pkgver/$_pkgname_skin-$pkgver.tar.gz
	https://github.com/messagerie-melanie2/$_pkgname_jquery/archive/v$_pkgver_jquery/$_pkgname_jquery-$_pkgver_jquery.tar.gz
	"

_confdir="etc/roundcube/plugins"
_rcdir="usr/share/webapps/roundcube"

prepare() {
	cd "$srcdir"

	find . -type f -exec chmod -x {} +
	rm -f */.gitignore */composer.json */package.xml */LICENCE */README.*
}

package() {
	local plugdir="$pkgdir/$_rcdir/plugins"
	local skindir="$pkgdir/$_rcdir/skins"

	cd "$srcdir"

	mkdir -p "$plugdir"
	cp -r "$_pkgname_jquery-$_pkgver_jquery" "$plugdir"/jquery_mobile
	cp -r "$_pkgname_plugin-$pkgver" "$plugdir"/mobile
	rm -R "$plugdir"/mobile/plugins

	mkdir -p "$skindir"
	cp -r "$_pkgname_skin-$pkgver" "$skindir"/melanie2_larry_mobile

	install -m 644 -g roundcube -D "$plugdir"/mobile/config.inc.php.dist \
		"$pkgdir"/$_confdir/mobile.inc.php
	ln -s /$_confdir/mobile.inc.php "$plugdir"/mobile/config.inc.php
}

_plugin() {
	local subname="${subpkgname#$pkgname-}"
	local plugdir="$subpkgdir/$_rcdir/plugins"

	pkgdesc="$pkgdesc (skin for $subname)"
	install_if="$pkgname=$pkgver-r$pkgrel roundcubemail-$subname"

	cd "$srcdir/$_pkgname_plugin-$pkgver"

	mkdir -p "$plugdir"/$subname
	cp -r plugins/$subname/skins "$plugdir"/$subname/
}

sha512sums="7370cb1f20faee5e90084ac90e2af50613ac1cce2e0f00f034393c8abe47106e3ce51e3abddec422b3b8a13ad081c0bb85f2791f8ce409e40c3c466469c81045  Roundcube-Plugin-Mobile-0.4.9.tar.gz
c3d58335e26f85876a126d65c377fb98a1d8c6753777f46e89f1658fef83bafaea228ec98935725ae9f53e1492f552047b41b59e596c713cea705ee0893e3ab6  Roundcube-Skin-Melanie2-Larry-Mobile-0.4.9.tar.gz
e29c08b8a3299ecc0c4a5127dce90c00e7682b2ee9c1c884a4faa0d6b3550c3ab63ae52fdf363c002831098406492596a275c1ac6242db0dea6ed1568e96b655  Roundcube-Plugin-JQuery-Mobile-1.2.tar.gz"
